/*
 * Copyright (c) 2010-2013 Ruben Chakhmakhchyan. All rights reserved.
 * 
 * This file contains Original Code and/or Modifications of Original Code
 * as defined in and that are subject to the Eclipse Public License
 * Version 1.0 (the 'License'). You may not use this file except in
 * compliance with the License. Please obtain a copy of the License at
 * http://opensource.org/licenses/EPL-1.0 and read it before using this file.
 */

#pragma once

#include "commontypes.h"


class CcittEncoder
{
public:

    CcittEncoder() : m_bp( 0 ) { }

    // source is byte-aligned
    // @bitsInverted - specifies whether the image colors are inverted, i.e. 1 - white, 0 - black (normally should be 0 - white, 1 - black)
    int encodeG4( byte_t* dest, byte_t* source, int width, int height, byte_t alignment, char direction, bool bitsInverted );

private:

    // returns the index of the next chaging element (differing from the one identified by 'bit' parameter) to the right of 'startIndex' element
    int findChangingElement( byte_t* line, int startIndex, int width, byte_t bit, byte_t& value );

    // finds to specified bit in the line
    byte_t getBit( byte_t* bytes, int index );

    // writes number of bits to the output buffer and updates the buffer pointer
    void writeByte( byte_t* buffer, byte_t bits, int number );
    void writeShort( byte_t* buffer, unsigned short bits, int number );
    void writeRunLength( byte_t* buffer, unsigned short length, byte_t bit );

private:

    int m_bp; // bit buffer pointer

    bool m_invertBits;
};
